// $ANTLR 3.4 ./src/main/java/hero/antlr/Expr3.g 2011-11-29 22:42:20
package hero.antlr;

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.runtime.tree.*;


@SuppressWarnings({"all", "warnings", "unchecked"})
public class Expr3Parser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "DOC", "ID", "INT", "NEWLINE", "SHIT", "TITLE", "WS", "'('", "')'", "'+'", "'-'"
    };

    public static final int EOF=-1;
    public static final int T__11=11;
    public static final int T__12=12;
    public static final int T__13=13;
    public static final int T__14=14;
    public static final int DOC=4;
    public static final int ID=5;
    public static final int INT=6;
    public static final int NEWLINE=7;
    public static final int SHIT=8;
    public static final int TITLE=9;
    public static final int WS=10;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public Expr3Parser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public Expr3Parser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

protected TreeAdaptor adaptor = new CommonTreeAdaptor();

public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
    public String[] getTokenNames() { return Expr3Parser.tokenNames; }
    public String getGrammarFileName() { return "./src/main/java/hero/antlr/Expr3.g"; }


    public static class expr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "expr"
    // ./src/main/java/hero/antlr/Expr3.g:14:1: expr : atom1 ( ( '+' | '-' ) atom2 )* NEWLINE -> ^( 'expr' atom1 ) ;
    public final Expr3Parser.expr_return expr() throws RecognitionException {
        Expr3Parser.expr_return retval = new Expr3Parser.expr_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token char_literal2=null;
        Token char_literal3=null;
        Token NEWLINE5=null;
        Expr3Parser.atom1_return atom11 =null;

        Expr3Parser.atom2_return atom24 =null;


        Object char_literal2_tree=null;
        Object char_literal3_tree=null;
        Object NEWLINE5_tree=null;
        RewriteRuleTokenStream stream_NEWLINE=new RewriteRuleTokenStream(adaptor,"token NEWLINE");
        RewriteRuleTokenStream stream_13=new RewriteRuleTokenStream(adaptor,"token 13");
        RewriteRuleTokenStream stream_14=new RewriteRuleTokenStream(adaptor,"token 14");
        RewriteRuleSubtreeStream stream_atom1=new RewriteRuleSubtreeStream(adaptor,"rule atom1");
        RewriteRuleSubtreeStream stream_atom2=new RewriteRuleSubtreeStream(adaptor,"rule atom2");
        try {
            // ./src/main/java/hero/antlr/Expr3.g:14:5: ( atom1 ( ( '+' | '-' ) atom2 )* NEWLINE -> ^( 'expr' atom1 ) )
            // ./src/main/java/hero/antlr/Expr3.g:14:9: atom1 ( ( '+' | '-' ) atom2 )* NEWLINE
            {
            pushFollow(FOLLOW_atom1_in_expr58);
            atom11=atom1();

            state._fsp--;

            stream_atom1.add(atom11.getTree());

            // ./src/main/java/hero/antlr/Expr3.g:14:15: ( ( '+' | '-' ) atom2 )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( ((LA2_0 >= 13 && LA2_0 <= 14)) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // ./src/main/java/hero/antlr/Expr3.g:14:16: ( '+' | '-' ) atom2
            	    {
            	    // ./src/main/java/hero/antlr/Expr3.g:14:16: ( '+' | '-' )
            	    int alt1=2;
            	    int LA1_0 = input.LA(1);

            	    if ( (LA1_0==13) ) {
            	        alt1=1;
            	    }
            	    else if ( (LA1_0==14) ) {
            	        alt1=2;
            	    }
            	    else {
            	        NoViableAltException nvae =
            	            new NoViableAltException("", 1, 0, input);

            	        throw nvae;

            	    }
            	    switch (alt1) {
            	        case 1 :
            	            // ./src/main/java/hero/antlr/Expr3.g:14:17: '+'
            	            {
            	            char_literal2=(Token)match(input,13,FOLLOW_13_in_expr62);  
            	            stream_13.add(char_literal2);


            	            }
            	            break;
            	        case 2 :
            	            // ./src/main/java/hero/antlr/Expr3.g:14:21: '-'
            	            {
            	            char_literal3=(Token)match(input,14,FOLLOW_14_in_expr64);  
            	            stream_14.add(char_literal3);


            	            }
            	            break;

            	    }


            	    pushFollow(FOLLOW_atom2_in_expr67);
            	    atom24=atom2();

            	    state._fsp--;

            	    stream_atom2.add(atom24.getTree());

            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            NEWLINE5=(Token)match(input,NEWLINE,FOLLOW_NEWLINE_in_expr72);  
            stream_NEWLINE.add(NEWLINE5);


            // AST REWRITE
            // elements: atom1, SHIT
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 14:43: -> ^( 'expr' atom1 )
            {
                // ./src/main/java/hero/antlr/Expr3.g:14:46: ^( 'expr' atom1 )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(
                (Object)adaptor.create(SHIT, "SHIT")
                , root_1);

                adaptor.addChild(root_1, stream_atom1.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }


            retval.tree = root_0;

            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "expr"


    public static class atom2_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "atom2"
    // ./src/main/java/hero/antlr/Expr3.g:16:1: atom2 : ( INT | ID | '(' expr ')' );
    public final Expr3Parser.atom2_return atom2() throws RecognitionException {
        Expr3Parser.atom2_return retval = new Expr3Parser.atom2_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token INT6=null;
        Token ID7=null;
        Token char_literal8=null;
        Token char_literal10=null;
        Expr3Parser.expr_return expr9 =null;


        Object INT6_tree=null;
        Object ID7_tree=null;
        Object char_literal8_tree=null;
        Object char_literal10_tree=null;

        try {
            // ./src/main/java/hero/antlr/Expr3.g:16:6: ( INT | ID | '(' expr ')' )
            int alt3=3;
            switch ( input.LA(1) ) {
            case INT:
                {
                alt3=1;
                }
                break;
            case ID:
                {
                alt3=2;
                }
                break;
            case 11:
                {
                alt3=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 3, 0, input);

                throw nvae;

            }

            switch (alt3) {
                case 1 :
                    // ./src/main/java/hero/antlr/Expr3.g:16:8: INT
                    {
                    root_0 = (Object)adaptor.nil();


                    INT6=(Token)match(input,INT,FOLLOW_INT_in_atom288); 
                    INT6_tree = 
                    (Object)adaptor.create(INT6)
                    ;
                    adaptor.addChild(root_0, INT6_tree);


                    }
                    break;
                case 2 :
                    // ./src/main/java/hero/antlr/Expr3.g:17:7: ID
                    {
                    root_0 = (Object)adaptor.nil();


                    ID7=(Token)match(input,ID,FOLLOW_ID_in_atom296); 
                    ID7_tree = 
                    (Object)adaptor.create(ID7)
                    ;
                    adaptor.addChild(root_0, ID7_tree);


                    }
                    break;
                case 3 :
                    // ./src/main/java/hero/antlr/Expr3.g:18:7: '(' expr ')'
                    {
                    root_0 = (Object)adaptor.nil();


                    char_literal8=(Token)match(input,11,FOLLOW_11_in_atom2104); 
                    char_literal8_tree = 
                    (Object)adaptor.create(char_literal8)
                    ;
                    adaptor.addChild(root_0, char_literal8_tree);


                    pushFollow(FOLLOW_expr_in_atom2106);
                    expr9=expr();

                    state._fsp--;

                    adaptor.addChild(root_0, expr9.getTree());

                    char_literal10=(Token)match(input,12,FOLLOW_12_in_atom2108); 
                    char_literal10_tree = 
                    (Object)adaptor.create(char_literal10)
                    ;
                    adaptor.addChild(root_0, char_literal10_tree);


                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "atom2"


    public static class atom1_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "atom1"
    // ./src/main/java/hero/antlr/Expr3.g:21:1: atom1 : ( INT | ID | '(' expr ')' );
    public final Expr3Parser.atom1_return atom1() throws RecognitionException {
        Expr3Parser.atom1_return retval = new Expr3Parser.atom1_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token INT11=null;
        Token ID12=null;
        Token char_literal13=null;
        Token char_literal15=null;
        Expr3Parser.expr_return expr14 =null;


        Object INT11_tree=null;
        Object ID12_tree=null;
        Object char_literal13_tree=null;
        Object char_literal15_tree=null;

        try {
            // ./src/main/java/hero/antlr/Expr3.g:21:6: ( INT | ID | '(' expr ')' )
            int alt4=3;
            switch ( input.LA(1) ) {
            case INT:
                {
                alt4=1;
                }
                break;
            case ID:
                {
                alt4=2;
                }
                break;
            case 11:
                {
                alt4=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;

            }

            switch (alt4) {
                case 1 :
                    // ./src/main/java/hero/antlr/Expr3.g:21:8: INT
                    {
                    root_0 = (Object)adaptor.nil();


                    INT11=(Token)match(input,INT,FOLLOW_INT_in_atom1120); 
                    INT11_tree = 
                    (Object)adaptor.create(INT11)
                    ;
                    adaptor.addChild(root_0, INT11_tree);


                    }
                    break;
                case 2 :
                    // ./src/main/java/hero/antlr/Expr3.g:22:7: ID
                    {
                    root_0 = (Object)adaptor.nil();


                    ID12=(Token)match(input,ID,FOLLOW_ID_in_atom1128); 
                    ID12_tree = 
                    (Object)adaptor.create(ID12)
                    ;
                    adaptor.addChild(root_0, ID12_tree);


                    }
                    break;
                case 3 :
                    // ./src/main/java/hero/antlr/Expr3.g:23:7: '(' expr ')'
                    {
                    root_0 = (Object)adaptor.nil();


                    char_literal13=(Token)match(input,11,FOLLOW_11_in_atom1136); 
                    char_literal13_tree = 
                    (Object)adaptor.create(char_literal13)
                    ;
                    adaptor.addChild(root_0, char_literal13_tree);


                    pushFollow(FOLLOW_expr_in_atom1138);
                    expr14=expr();

                    state._fsp--;

                    adaptor.addChild(root_0, expr14.getTree());

                    char_literal15=(Token)match(input,12,FOLLOW_12_in_atom1140); 
                    char_literal15_tree = 
                    (Object)adaptor.create(char_literal15)
                    ;
                    adaptor.addChild(root_0, char_literal15_tree);


                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "atom1"

    // Delegated rules


 

    public static final BitSet FOLLOW_atom1_in_expr58 = new BitSet(new long[]{0x0000000000006080L});
    public static final BitSet FOLLOW_13_in_expr62 = new BitSet(new long[]{0x0000000000000860L});
    public static final BitSet FOLLOW_14_in_expr64 = new BitSet(new long[]{0x0000000000000860L});
    public static final BitSet FOLLOW_atom2_in_expr67 = new BitSet(new long[]{0x0000000000006080L});
    public static final BitSet FOLLOW_NEWLINE_in_expr72 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INT_in_atom288 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_atom296 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_11_in_atom2104 = new BitSet(new long[]{0x0000000000000860L});
    public static final BitSet FOLLOW_expr_in_atom2106 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_12_in_atom2108 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INT_in_atom1120 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_atom1128 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_11_in_atom1136 = new BitSet(new long[]{0x0000000000000860L});
    public static final BitSet FOLLOW_expr_in_atom1138 = new BitSet(new long[]{0x0000000000001000L});
    public static final BitSet FOLLOW_12_in_atom1140 = new BitSet(new long[]{0x0000000000000002L});

}